﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace Akronus.TaskScheduler.Logging
{
    public class TaskLog : ITaskLog
    {
        public TaskLog()
        {

        }

        public virtual void Add(string message)
        {
            this.Add(message, LogPriority.High);
        }

        public virtual void Add(string message, string priority)
        {
            string category = "Task";
            int logPriority;

            switch (priority)
            {
                case LogPriority.High:
                    logPriority = 3;
                    break;
                default:
                    logPriority = 1;
                    break;
            }

            if (!string.IsNullOrEmpty(message) && !string.IsNullOrEmpty(category))
            {
                try
                {
                    LogEntry entry = new LogEntry();
                    entry.Message = message;
                    entry.Priority = logPriority;
                    entry.Title = string.Empty;
                    entry.Categories.Add(category);
                    Logger.Write(entry);
                }
                catch
                {
                    //No exception can be raised here since there will be an endless loop when 
                    //general exception handling will be using this logging class as well.
                }
            }
        }
    }
}
